package com.tbq.tbqj_ggl.windows

import android.app.Activity
import android.graphics.Bitmap
import android.view.View
import com.tbq.sdk.L

import com.tbq.sdk.TBQ
import com.tbq.sdk.TBQ_V
import com.tbq.tbqj_ggl.R
import com.tbq.tbqj_ggl.app.AppBasePopupWindow
import com.tbq.tbqj_ggl.utils.ScreenUtil
import com.zxy.tiny.Tiny


/**
 * Created by hais1992 on 2016/1/26/026.
 */
class TowerGameExitWindows(activity: Activity) : AppBasePopupWindow(activity,
        if(TBQ.get("KEY_IS_MOBILE") == "1") R.layout.mobile_windows_tower_game_exit else  R.layout.windows_tower_game_exit) {
    private var image_fhyx: View? = null
    private var image_ok: View? = null

    override fun drawEnd(v: View) {
        image_fhyx = v.findViewById(R.id.image_fhyx)
        image_ok = v.findViewById(R.id.image_ok)
        image_ok!!.setOnClickListener(this)
        image_fhyx!!.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view.id) {
            R.id.image_ok -> {
                if (TBQ.get("KEY_IS_MOBILE") != "1") {
                    val options = Tiny.FileCompressOptions()
                    options.quality = 50    //质量
                    options.isKeepSampling = true   //保存默认宽高
                    options.outfile = "/sdcard/TBQ_FILE/Screenshot/${TBQ.get(TBQ_V.KEY_RAFFLE_TICKET_ID)}_Game_${TBQ.get("KEY_ADMIN_ID")}.jpg"
                    options.config = Bitmap.Config.RGB_565
                    Tiny.getInstance().source(ScreenUtil.snapShotWithStatusBar(activity)).asFile().withOptions(options).compress { isSuccess, outfile ->
                        L.e("GGL", "图片处理结果：$isSuccess,$outfile")
                        TBQ.openTBQ(activity, false, -110)
                        activity.finish()
                    }
                }else{
                    TBQ.openTBQ(activity, false, -110)
                    activity.finish()
                }
            }
            R.id.image_fhyx -> dismiss()
        }
    }
}
